package cn.groupmarket.types.design.framework.link.model2.chain;

import cn.groupmarket.types.design.framework.link.model2.handler.ILogicHandler;

public class BusinessLinkedList<T,D,R> extends LinkedList<ILogicHandler<T,D,R>> implements ILogicHandler<T,D,R> {
    public BusinessLinkedList(String name) {
        super(name);
    }

    @Override
    public R apply(T requestParameter, D dynamicContext) throws Exception {
        Node<ILogicHandler<T,D,R>> cur = this.first;
        for(;cur != null;cur = cur.next) {
            ILogicHandler<T,D,R> item = cur.item;
            R apply = item.apply(requestParameter, dynamicContext);
            if(apply != null) {
                return apply;
            }
        }
        return null;
    }
}
